<?php

class NoticiasController extends BaseController {

	public function index()
	{
		$noticias = Noticia::orderBy('created_at','DESC')->paginate(3);
		
		$title='Noticias :: Paintballed';
		
		return View::make('contents.noticias',compact('title','noticias'));
	}
	
	public function noticia($id){
		
		$noticia = Noticia::find($id);
		
		$validator = Validator::make(Input::all(), array(
			'comentario'=>'required'		
		));
		
		if($validator->passes()){
			$comentario= new Comentario();
			$comentario->contenido=Input::get('comentario');
			
			Auth::user()->comentarios()->save($comentario);
			
			$noticia->comentarios()->attach($comentario);
		}
		
		$title=$noticia->titulo.' :: Paintballed';
		
		return View::make('contents.noticia',compact('title','noticia'));
	}
	
	

}